{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "05a3e776",
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "from torch import nn\n",
    "\n",
    "class cnn(nn.Module):\n",
    "    def __init__(self,num_class=10):\n",
    "        super.__init__()\n",
    "        self.conv1=nn.Conv2d(in_channels=3,out_channels=32,kernel_size=3,stride=1)\n",
    "        self.bn1=nn.BatchNorm2d(32)\n",
    "        self.relu1=nn.ReLU()\n",
    "        self.pool1=nn.MaxPool2d(kernel_size=2,stride=2)\n",
    "\n",
    "        self.conv2=nn.Conv2d(32,64,3,1)\n",
    "        self.bn2=nn.BatchNorm2d(64)\n",
    "        self.relu2=nn.ReLU()\n",
    "        self.pool2=nn.MaxPool2d(2,2)\n",
    "\n",
    "        self.conv3=nn.Conv2d(64,128,3,1)\n",
    "        self.bn3=nn.BatchNorm2d(128)\n",
    "        self.relu3=nn.ReLU()\n",
    "        self.pool3=nn.MaxPool2d(2,2)\n",
    "\n",
    "        # # 假设输入图像大小为28x28，经过3次池化后大小为3x3\n",
    "        self.fc1=nn.Linear(128*3*3,512)\n",
    "        self.dropout=nn.Dropout(0.5)\n",
    "        self.fc2=nn.Linear(512,num_class)\n",
    "\n",
    "    def forward(self,x):\n",
    "        x=self.conv1(x)\n",
    "        x=self.bn1(x)\n",
    "        x=self.relu1(x)\n",
    "        x=self.pool1(x)\n",
    "\n",
    "        x=self.conv2(x)\n",
    "        x=self.bn2(x)\n",
    "        x=self.relu2(x)\n",
    "        x=self.pool2(x)\n",
    "\n",
    "        x=self.conv3(x)\n",
    "        x=self.bn3(x)\n",
    "        x=self.relu3(x)\n",
    "\n",
    "        x=x.view(x.size(0),-1)\n",
    "\n",
    "        x=self.fc1(x)\n",
    "        x=self.relu1(x)\n",
    "        x=self.dropout(x)\n",
    "        x=self.fc2(x)\n",
    "\n",
    "        return x\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "970e0aaf",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "cv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
